﻿using System.Web.Mvc;
using Orchard;
using Orchard.Localization;
using Orchard.UI.Notify;
using SuperClassic.Services;
using SuperClassic.ViewModels;

namespace SuperClassic.Controllers {
    public class AdminController : Controller {
        private readonly ISettingsService _settingsService;

        public AdminController(
            IOrchardServices services, 
            ISettingsService settingsService)
        {
            _settingsService = settingsService;
            Services = services;
            T = NullLocalizer.Instance;
        }

        public IOrchardServices Services { get; set; }
        public Localizer T { get; set; }

        public ActionResult Index() {
            var settings = _settingsService.GetSettings();

            var viewModel = new SettingsViewModel {
                FontFamily = settings.FontFamily,
                AlternateCss = settings.AlternateCss
            };

            return View(viewModel);
        }

        [HttpPost]
        public ActionResult Index(SettingsViewModel viewModel) {
            var settings = _settingsService.GetSettings();

            settings.FontFamily = viewModel.FontFamily;
            settings.AlternateCss = viewModel.AlternateCss;

            Services.Notifier.Information(T("Your settings have been saved."));

            return View(viewModel);
        }

    }
}